package cn.myfirefly.moming.integrate.dao;

import java.util.Date;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import cn.myfirefly.moming.integrate.entity.MMWorkCalendar;
import cn.myfirefly.core.BaseDao;

@Repository
public class WorkCalendarDao extends BaseDao<MMWorkCalendar>{
	
	@SuppressWarnings("unchecked")
	public List<MMWorkCalendar> getAll(){
		Session session = sessionFactory.getCurrentSession();
		Query query = session.createQuery("from MMWorkCalendar w ");
		List<MMWorkCalendar> list = query.list();
		return list;
	}
	
	@SuppressWarnings("unchecked")
	public List<MMWorkCalendar> getNoWorkDate(Date startDate, Date endDate){
		Session session = sessionFactory.getCurrentSession();
		Query query = session.createQuery("from MMWorkCalendar w where date_type='1' and date_value>=:startDate and date_value<=:endDate ");
		query.setDate("startDate", startDate);
		query.setDate("endDate", endDate);
		List<MMWorkCalendar> list = query.list();
		return list;
	}
	
	@SuppressWarnings("unchecked")
	public MMWorkCalendar getWorkDate(Date dateValue) {
		Session session = sessionFactory.getCurrentSession();
		MMWorkCalendar workCalendar = null;
		Query query = session.createQuery("from MMWorkCalendar w where w.dateValue=:dateValue ");
		query.setDate("dateValue", dateValue);
		List<MMWorkCalendar> list = query.list();
		if (list != null && list.size() > 0) {
			workCalendar = list.get(0);
		}
		return workCalendar;
	}
	
}
